﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace remote_config_tools
{
    public delegate void UpdateLabelInfo(Label lb,string state);
    public delegate void UpdateTextboxInfo(TextBox tb, string state);
    public delegate void UpdateProgressInfo(ProgressBar pb, int pos); 
    public delegate void UpdateButtonInfo(Button bt, bool set);
    public class control_classs
    {
        private Form1 form;
        public control_classs(Form1 form)
        {
            this.form = form;
        }
        /// <summary>
        /// 更新状态栏
        /// </summary>
        /// <param name="tss"></param>
        /// <param name="lss"></param>
        /// <param name="op"></param>
        /// <param name="state"></param>
        public void UpStatusToolCtrlText(StatusStrip tss, ToolStripStatusLabel lss, string op, string state)
        {
            if (tss.InvokeRequired)
            {
                tss.Invoke(
                    new MethodInvoker(() => lss.Text = op + "---" + state)
                    );
            }
            else
            {
                lss.Text = op + "---" + state;
            }
        }
        /// <summary>
        /// 更新label值
        /// </summary>
        /// <param name="lb"></param>
        /// <param name="text"></param>
        public void UpLabelText(Label lb,string text)
        {
            if (lb.InvokeRequired)
            {
                lb.Invoke(new UpdateLabelInfo(UpLabelText), new object[] { lb,text });
            }
            else
            {
                lb.Text = text;
            }
        }
        /// <summary>
        /// 更新文本框
        /// </summary>
        /// <param name="tb"></param>
        /// <param name="text"></param>
        public void UpTextBoxText(TextBox tb,string text)
        {
            if (tb.InvokeRequired)
            {
                tb.Invoke(new UpdateTextboxInfo(UpTextBoxText), new object[] { tb, text });
            }
            else
            {
                tb.Text = text;
            }
        }
        /// <summary>
        /// 更新进度条最大值
        /// </summary>
        /// <param name="tb"></param>
        /// <param name="text"></param>
        public void UpdataProgessMax(ProgressBar pb,int pos)
        {
            if (pb.InvokeRequired)
            {
                pb.Invoke(new UpdateProgressInfo(UpdataProgessMax), new object[] { pb, pos });
            }
            else
            {
                pb.Maximum = pos;
            }
        }
        /// <summary>
        /// 更新进度条最小值
        /// </summary>
        /// <param name="pb"></param>
        /// <param name="pos"></param>
        public void UpdataProgessMin(ProgressBar pb, int pos)
        {
            if (pb.InvokeRequired)
            {
                pb.Invoke(new UpdateProgressInfo(UpdataProgessMin), new object[] { pb, pos });
            }
            else
            {
                pb.Minimum = pos;
            }
        }
        /// <summary>
        /// 更新进度条当前值
        /// </summary>
        /// <param name="pb"></param>
        /// <param name="pos"></param>
        public void UpdataProgessValue(ProgressBar pb, int pos)
        {
            if (pb.InvokeRequired)
            {
                pb.Invoke(new UpdateProgressInfo(UpdataProgessValue), new object[] { pb, pos });
            }
            else
            {
                pb.Value = pos;
            }
        }
        /// <summary>
        /// 更新进度条当前值
        /// </summary>
        /// <param name="pb"></param>
        /// <param name="pos"></param>
        public void UpdataButtonEnable(Button bt,bool set)
        {
            if (bt.InvokeRequired)
            {
                bt.Invoke(new UpdateButtonInfo(UpdataButtonEnable), new object[] { bt,set });
            }
            else
            {
                bt.Enabled = set;
            }
        }
    }

}
